package com.zjs.jsp.fdservice.service;


import com.currencyboot.service.rocketmq.MqProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.UnsupportedEncodingException;

/**
 * 任务消息下发类
 *
 * @author 李文
 * @create 2017-09-01 17:02
 **/
@Service
public class Producer
{
    @Autowired
    private MqProducer mqProducer;


    @Value("${JSP.Topic}")
    private String jspTopic;

    @Value("${Topic}")
    private String Topic;
    /**
     * 追加订单下发
     */
    @Value("${JSP.TagsZD}")
    private String TagsZD;

    /**
     * 首次下发订单
     */
    @Value("${JSP.Tags}")
    private String Tags;


    /**
     * 订单接受成功
     */
    @Value("${Tags}")
    private String TagsCD;

    /**
     * 发送 任务包数据  到MQ
     *
     * @param jspTask  首次下发 发送任务包
     * @param addOrder 追加订单 发送 数据类
     * @throws UnsupportedEncodingException
     */
    public SendResult sendMQ(String jspTask, String addOrder, String poc) throws UnsupportedEncodingException {
        if (jspTask == null) {
            return mqProducer.send(jspTopic, TagsZD, addOrder);
        }
        if (addOrder == null) {
            return mqProducer.send(jspTopic, Tags, jspTask);
        }
        //  发送订单接受成功MQ
        return mqProducer.send(Topic, TagsCD,
                "{\"taskCode\":null,\"orderCode\":\"" + poc + "\",\"status\":\"00\",\"excpCode\":\"\",\"excpNote\":\"\"}");

    }

}
